package com.eboss.sbs.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ScrollView;

import com.eboss.sbs.R;
import com.eboss.sbs.activity.base.BaseActivity;
import com.eboss.sbs.enums.EnumConsts;
import com.eboss.sbs.http.API;
import com.eboss.sbs.http.HttpCallback;
import com.eboss.sbs.model.WalletDrawLogDetail;
import com.google.gson.reflect.TypeToken;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
import com.handmark.pulltorefresh.library.PullToRefreshScrollView;
import com.mytools.tool.utils.StringUtil;
import com.mytools.tool.utils.TimeUtil;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class MyWalletDrawLogDetailActivity extends BaseActivity {

	private PullToRefreshScrollView scroolView;
	
	private int logid;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		mActivity = this;
		setContentView(R.layout.activity_my_wallet_drawlog_detail);
		super.onCreate(savedInstanceState);
		initView();
		getdata();
	}
	
	private void initView(){
		showView(R.id.titleback_btn_back, true);
		setTvText(R.id.tv_title, "提现详情");
		
		logid = getIntent().getIntExtra("logid", -1);
		
		scroolView = (PullToRefreshScrollView) findViewById(R.id.scroolView);
		scroolView.setMode(Mode.PULL_DOWN_TO_REFRESH);
		scroolView.setOnRefreshListener(new PullToRefreshViewEvent()); //下拉刷新 上拉加载
		
		findViewById(R.id.titleback_btn_back).setOnClickListener(this);
	}
	
	//下拉刷新 上拉加载
	public class PullToRefreshViewEvent implements OnRefreshListener<ScrollView>{
		@Override
		public void onRefresh(PullToRefreshBase<ScrollView> refreshView) {
			getdata();
		}
	}
	
	private void getdata(){
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("sid", mApp.getLoginEntity().getSid());
		params.put("logid", logid);
		
		API.http_post(this, API.WALLET_DRAW_LOG_DETAIL, params, new HttpCallback<WalletDrawLogDetail>(this) {
			@Override
			public void onSuccess(int statusCode, WalletDrawLogDetail data) {

				
				
				scroolView.onRefreshComplete();
			}

			@Override
			public void onFailure(int statusCode, String message) {
				
				//------------  this part below is test part ------------------//
				WalletDrawLogDetail data_tmp = new WalletDrawLogDetail(1, 1234, Long.parseLong("1462525252432"), "China Bank", "Shanghai PuDong Branch", "zhangsan", "No8646545645");
				setTvText(R.id.tv_status, ""+ EnumConsts.WalletDrawStatus.getNameByStatus(data_tmp.getStatus()));
				setTvText(R.id.tv_drawMoney, ""+ StringUtil.getMoneyString(data_tmp.getDrawMoney())+"元");
				setTvText(R.id.tv_requestTime, TimeUtil.getStringFromDate(new Date(data_tmp.getRequestTime()), "yyyy-MM-dd HH:mm:ss"));
				setTvText(R.id.tv_bank, ""+data_tmp.getBank());
				setTvText(R.id.tv_branch, ""+data_tmp.getBranch());
				setTvText(R.id.tv_accountName, ""+data_tmp.getAccountName());
				setTvText(R.id.tv_accountNo, ""+data_tmp.getAccountNo());
				//------------  this part above is test part ------------------//
				
				scroolView.onRefreshComplete();
				super.onFailure(statusCode, message);
			}
			
			@SuppressWarnings({ "unchecked", "rawtypes" })
			@Override
			public TypeToken getTypeToken() {
				return new TypeToken<WalletDrawLogDetail>() {
				};
			}
		});
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.titleback_btn_back:
				finish();
				break;
			case R.id.ly_draw_log:
				
				break;
			case R.id.ly_draw_accounts:
				
				break;
			default:break;
		}
		super.onClick(v);
	}
	
}
